package com.wuchaooooo.service.zjutsds.service;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wuchaooooo.service.zjutsds.dao.ScoreDAO;
import com.wuchaooooo.service.zjutsds.pojo.vo.VScore;

/**
 * Created by arthur on 01/31/2020.
 */
@Service
public class ScoreService {
    @Autowired
    private ScoreDAO scoreDAO;

    public Map<String, List<VScore>> getUniList(VScore vScore) {
    	
        List<VScore> uniList = scoreDAO.getUniList(vScore);
        
        String uniName = null;
        List<VScore> list = null;
        Map<String, List<VScore>> map = new LinkedHashMap <String, List<VScore>>();
        for(VScore s : uniList) {
        	if(!s.getName().equals(uniName)) {
        		uniName= s.getName();
        		String key = uniName + "," + getComment(s, vScore.getYear(),vScore.getScore());
        		list = new ArrayList<VScore>();
        		map.put(key, list);
        	}
        	list.add(s);
        }
        return map;
    }
    
    private String getComment(VScore vScore, String year, String iScore) {
    	int inputScore = Integer.parseInt(iScore);
        if("2019".equals(year)) {
        	if(StringUtils.isNumeric(vScore.getScore2019())) {
        		Integer score = Integer.parseInt(vScore.getScore2019());
        		
        		if(score - inputScore >= 0) {
        			return "冲";
        		} else if (score - inputScore >= -5) {
        			return "争";
        		} else if (score - inputScore >= -10) {
        			return "稳";
        		}
        	}
        } else if("2018".equals(year)) {
        	if(StringUtils.isNumeric(vScore.getScore2018())) {
        		Integer score = Integer.parseInt(vScore.getScore2018());
        		if(score - inputScore >= 0) {
        			return "冲";
        		} else if (score - inputScore >= -5) {
        			return "争";
        		} else if (score - inputScore >= -10) {
        			return "稳";
        		}
        	}
        } else if("2017".equals(year)) {
        	if(StringUtils.isNumeric(vScore.getScore2017())) {
        		Integer score = Integer.parseInt(vScore.getScore2017());
        		if(score - inputScore >= 0) {
        			return "冲";
        		} else if (score - inputScore >= -5) {
        			return "争";
        		} else if (score - inputScore >= -10) {
        			return "稳";
        		}
        	}
        }
        return "";
    }
}
